home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / ATTR.C next >
C/C++ Source or Header  |  1992-07-19  |  2KB  |  111 lines

  1. #include <stdio.h>
  2. #include "vogl.h"
  3.  
  4. static    Astack    *asfree = (Astack *)NULL;
  5.  
  6. /*
  7.  * copyattributes
  8.  *
  9.  *    Copies attribute stack entries from b to a
  10.  */
  11. static    void
  12. copyattributes(a, b)
  13.     Attribute    *a, *b;
  14. {
  15.     a->color = b->color;
  16.     a->fontwidth = b->fontwidth;
  17.     a->fontheight = b->fontheight;
  18.     a->fontnum = b->fontnum;
  19. }
  20.  
  21. /*
  22.  * pushattributes
  23.  *
  24.  * save the current attributes on the matrix stack
  25.  *
  26.  */
  27. void
  28. pushattributes()
  29. {
  30.     Astack    *nattr;
  31.     Token    *p;
  32.  
  33.     if (!vdevice.initialised)
  34.         verror("pushattributes:  vogl not initialised");
  35.     
  36.     if (vdevice.inobject) {
  37.         p = newtokens(1);
  38.  
  39.         p[0].i = PUSHATTRIBUTES;
  40.  
  41.         return;
  42.     }
  43.  
  44.     if (asfree != (Astack *)NULL) {
  45.         nattr = vdevice.attr;
  46.         vdevice.attr = asfree;
  47.         asfree = asfree->back;
  48.         vdevice.attr->back = nattr;
  49.         copyattributes(&vdevice.attr->a, &nattr->a);
  50.     } else {    
  51.         nattr = (Astack *)vallocate(sizeof(Astack));
  52.         nattr->back = vdevice.attr;
  53.         copyattributes(&nattr->a, &vdevice.attr->a);
  54.         vdevice.attr = nattr;
  55.     }
  56. }
  57.  
  58. /*
  59.  * popattributes
  60.  *
  61.  * pop the top entry on the attribute stack 
  62.  *
  63.  */
  64. void
  65. popattributes()
  66. {
  67.     Astack    *nattr;
  68.     Token    *p;
  69.  
  70.     if (!vdevice.initialised)
  71.         verror("popattributes: vogl not initialised");
  72.     
  73.     if (vdevice.inobject) {
  74.         p = newtokens(1);
  75.  
  76.         p[0].i = POPATTRIBUTES;
  77.  
  78.         return;
  79.     }
  80.  
  81.     if (vdevice.attr->back == (Astack *)NULL) 
  82.         verror("popattributes: attribute stack is empty");
  83.     else {
  84.         font(vdevice.attr->back->a.fontnum);
  85.         nattr = vdevice.attr;
  86.         vdevice.attr = vdevice.attr->back;
  87.         nattr->back = asfree;
  88.         asfree = nattr;
  89.     }
  90.  
  91.     color(vdevice.attr->a.color);
  92. }
  93.  
  94. #ifdef    DEBUG
  95.  
  96. printattribs(s)
  97.     char    *s;
  98. {
  99.     printf("%s\n", s);
  100.     printf("clipoff    = %d\n", vdevice.clipoff);
  101.     printf("color      = %d\n", vdevice.attr->a.color);
  102.     printf("textcos    = %f\n", vdevice.attr->a.textcos);
  103.     printf("textsin    = %f\n", vdevice.attr->a.textsin);
  104.     printf("fontwidth  = %f\n", vdevice.attr->a.fontwidth);
  105.     printf("fontwidth  = %f\n", vdevice.attr->a.fontheight);
  106.     printf("fontnum    = %d\n", vdevice.attr->a.fontnum);
  107.     printf("mode       = %d\n", vdevice.attr->a.mode);
  108. }
  109.  
  110. #endif
  111.